package com.yanqu.road.logic.activity;

import com.yanqu.road.entity.activity.huashigang.HuaShiGangActivityEventConfig;
import com.yanqu.road.entity.activity.huashigang.HuaShiGangStageBigTypeEvents;
import com.yanqu.road.entity.enums.activity.huashigang.eHuaShiGangEventType;
import com.yanqu.road.utils.string.StringUtils;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Author wpj
 * @Date 2020/10/5
 */
public class HuaShiGangLogic {
    public static void parseEventConfigParam(Collection<HuaShiGangActivityEventConfig> configList) {
        for (HuaShiGangActivityEventConfig config : configList) {
            if (eHuaShiGangEventType.isMonsterEvent(config.getEventType())) {
                // 怪物事件 解析参数
                List<String> paramList = StringUtils.stringToStringList(config.getParamList(), "\\|");
                int bloodParam = Integer.valueOf(paramList.get(0));
                int scoreParam = Integer.valueOf(paramList.get(1));
                int stage = Integer.valueOf(paramList.get(2));

                config.setBloodParam(bloodParam);
                config.setKillScoreParam(scoreParam);
                config.setStage(stage);

            } else if (eHuaShiGangEventType.UNEXPECTED_EVENT.getValue() == config.getEventType()) {
                // 意外事件 客栈
                config.setAddition(Integer.valueOf(config.getParamList()));
            } else if (eHuaShiGangEventType.BOX_EVENT.getValue() == config.getEventType()) {
                List<Integer> paramList = StringUtils.stringToIntegerList(config.getParamList(), "\\|");
                config.setOpenCostKeyId(paramList.get(0));
//                config.setBoxRewardNum(paramList.get(1));
//                config.setBoxRewardList(StringUtils.stringToStringList(config.getRewards(), "\\|"));
            } else if (eHuaShiGangEventType.BOSS_TREASURE_EVENT.getValue() == config.getEventType()) {
                List<String> list = StringUtils.stringToStringList(config.getParamList(), "-");
                config.setStage(Integer.valueOf(list.get(1)));
            }
        }
    }

    /**
     * 构造阶段=>事件大类型=>事件列表 MAP
     * @param eventMap
     * @param stageList
     * @return
     */
    public static Map<Integer, Map<Integer, HuaShiGangStageBigTypeEvents>> createStageBigTypeEventsMap(Map<Integer, HuaShiGangActivityEventConfig> eventMap, List<List<Integer>> stageList) {
        Map<Integer, Map<Integer, HuaShiGangStageBigTypeEvents>> stageBigTypeEventsMap = new ConcurrentHashMap<>();
        //遍历一下阶段配置
        for (List<Integer> stage : stageList) {
            //阶段号
            int stageNum = stage.get(0);
            //模块事件MAP,k:事件大类型，v：HuaShiGangModeEvents
            Map<Integer, HuaShiGangStageBigTypeEvents> eventsMap = new HashMap<>();
            //遍历一下事件
            for (HuaShiGangActivityEventConfig eventConfig : eventMap.values()) {
                //获取事件大类型
                int bigType = eHuaShiGangEventType.getBigTypeByType(eventConfig.getEventType());
                if (bigType <= 0) {
                    continue;
                }
                //判断一下阶段是否符合
                if (eventConfig.getStage() != 0 && eventConfig.getStage() != stageNum) {
                    continue;
                }
                //注入事件
                HuaShiGangStageBigTypeEvents huaShiGangModeEvents = eventsMap.computeIfAbsent(bigType, k -> new HuaShiGangStageBigTypeEvents());
                huaShiGangModeEvents.addEvent(eventConfig);
                huaShiGangModeEvents.addWeight(eventConfig.getWeight());
            }
            stageBigTypeEventsMap.put(stageNum, eventsMap);
        }
        return stageBigTypeEventsMap;
    }
}
